/*
 * @author wilbur.ma@qq.com
 * @date 2011.06.01
 * Requrie jquery and jquery.url
 */
 
 function fold_all() {
	$("#hosts > div").each(function() {fold_div_id(this.id)});
 }
 
 function fold_all_except(div_id) {
	$("#hosts > div").each(function() {
			if (this.id != div_id)
				fold_div_id(this.id);
			else
				show_div_id(this.id);
		}
	);
 }
 
 function show_all() {
	$("#hosts > div").each(function() {show_div_id(this.id)});
 }
 
 function set_div_img_open(div_id) {
	set_div_img(div_id, true);
 }
 
 function set_div_img_closed(div_id) {
	set_div_img(div_id, false);
 }
 
 function set_div_img(div_id, state_p) {
	var img = $("#" + div_id + " img");
	if (state_p == true) {
		img.attr("src", "../img/open.png");
		img.attr("alt", "open");
	} else {
		img.attr("src", "../img/closed.png");
		img.attr("alt", "close");
	}
 }
 
 function fold_div_id(div_id) {
	$("#"+div_id+" div:nth-child(2)").hide("fast");
	set_div_img_closed(div_id);
 }
 
 function show_div_id(div_id) {
	$("#"+div_id+" div:nth-child(2)").show("fast");
	set_div_img_open(div_id);
 }
 
 function is_div_folded(div_id) {
	return $("#"+div_id+" div:nth-child(2)").is(":hidden");
 }
 
 function toggle_div_id(div_id) {
	if (is_div_folded(div_id))
		show_div_id(div_id);
	else
		fold_div_id(div_id);
 }
 
 function show_cur_host() {
	fold_all_except($.url().attr("fragment"));
 }
 
 window.onload = function(event) {
	$("#showall").click(function(event) { show_all(); });
	$("#hideall").click(function(event) { fold_all(); });
	$("#hosts > div").each(function() {$(this).click(function(event) { fold_all_except(this.id);})});
    show_cur_host();
};